package com.easy.service.impl;

import com.easy.bean.Itinerary_detail;
import com.easy.mapper.Itinerary_detailDao;
import com.easy.service.Itinerary_detailService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class Itinerary_detailServiceImpl implements Itinerary_detailService {

    private static final String CACHE_NAME = "itinerary_detail";

    @Autowired
    Itinerary_detailDao itinerary_detailDao;

    @Override

    public Itinerary_detail add(Itinerary_detail itinerary_detail) {
        // 新增数据
        itinerary_detailDao.add(itinerary_detail);
        // 通过主键查询数据库的数据
        Itinerary_detail result = itinerary_detailDao.one(itinerary_detail.getId());
        return result;
    }

    @Override

    public int del(Integer id) {
        return itinerary_detailDao.del(id);
    }

    @Override
    public Itinerary_detail edit(Itinerary_detail itinerary_detail) {
        itinerary_detailDao.edit(itinerary_detail);
        Itinerary_detail result = itinerary_detailDao.one(itinerary_detail.getId());
        return result;
    }

    @Override

    public List<Itinerary_detail> all(Itinerary_detail itinerary_detail) {
        return itinerary_detailDao.all(itinerary_detail);
    }

    @Override
    @Cacheable(value = CACHE_NAME, key = "'itinerary_detail:id:' + #p0", unless = "#result == null")
    public Itinerary_detail one(Integer id) {
        return itinerary_detailDao.one(id);
    }

    @Override
    public void page(Page page, Itinerary_detail itinerary_detail) {
        int count = itinerary_detailDao.pageCount(itinerary_detail);
        Object data = itinerary_detailDao.page(page, itinerary_detail);
        page.setCount(count);
        page.setData(data);
    }

    @Override
    public void pageWithDetails(Page page, Itinerary_detail itinerary_detail) {
        int count = itinerary_detailDao.pageCountWithDetails(itinerary_detail);
        Object data = itinerary_detailDao.pageWithDetails(page, itinerary_detail);
        page.setCount(count);
        page.setData(data);
    }
}
